package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZsyyServicePeopleVo;
import com.ruoyi.system.bo.ZsyyServicePeopleQueryBo;
import com.ruoyi.system.bo.ZsyyServicePeopleAddBo;
import com.ruoyi.system.bo.ZsyyServicePeopleEditBo;
import com.ruoyi.system.service.IZsyyServicePeopleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 服务人员管理Controller
 *
 * @author wangghua
 * @date 2021-07-14
 */
@ApiIgnore
@Api(value = "服务人员管理控制器", tags = {"服务人员管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/servicePeople")
public class ZsyyServicePeopleController extends BaseController {

    private final IZsyyServicePeopleService iZsyyServicePeopleService;

    /**
     * 查询服务人员管理列表
     */
    @ApiOperation("查询服务人员管理列表")
    @PreAuthorize("@ss.hasPermi('system:servicePeople:list')")
    @GetMapping("/list")
    public TableDataInfo<ZsyyServicePeopleVo> list(@Validated ZsyyServicePeopleQueryBo bo) {
        return iZsyyServicePeopleService.queryPageList(bo);
    }
    /**
     * 空闲的工作人员下拉列表
     */
    @ApiOperation("空闲的工作人员下拉列表")
    @GetMapping("/listByTemp")
    public AjaxResult listByTemp(@Validated ZsyyServicePeopleQueryBo bo) {
        return AjaxResult.success(iZsyyServicePeopleService.queryList(bo));
    }

    /**
     * 导出服务人员管理列表
     */
    @ApiOperation("导出服务人员管理列表")
    @PreAuthorize("@ss.hasPermi('system:servicePeople:export')")
    @Log(title = "服务人员管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZsyyServicePeopleVo> export(@Validated ZsyyServicePeopleQueryBo bo) {
        List<ZsyyServicePeopleVo> list = iZsyyServicePeopleService.queryList(bo);
        ExcelUtil<ZsyyServicePeopleVo> util = new ExcelUtil<ZsyyServicePeopleVo>(ZsyyServicePeopleVo.class);
        return util.exportExcel(list, "服务人员管理");
    }

    /**
     * 获取服务人员管理详细信息
     */
    @ApiOperation("获取服务人员管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:servicePeople:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZsyyServicePeopleVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZsyyServicePeopleService.queryById(id));
    }

    /**
     * 新增服务人员管理
     */
    @ApiOperation("新增服务人员管理")
    @PreAuthorize("@ss.hasPermi('system:servicePeople:add')")
    @Log(title = "服务人员管理", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZsyyServicePeopleAddBo bo) {
        return toAjax(iZsyyServicePeopleService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改服务人员管理
     */
    @ApiOperation("修改服务人员管理")
    @PreAuthorize("@ss.hasPermi('system:servicePeople:edit')")
    @Log(title = "服务人员管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZsyyServicePeopleEditBo bo) {
        return toAjax(iZsyyServicePeopleService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除服务人员管理
     */
    @ApiOperation("删除服务人员管理")
    @PreAuthorize("@ss.hasPermi('system:servicePeople:remove')")
    @Log(title = "服务人员管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZsyyServicePeopleService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
